import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author gaofei
 * @date 2022/6/9 19:28
 */
public class jsontest {
    @Data
    @AllArgsConstructor
    static class A {
        private Integer a;
        private String b;
    }

    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
        System.out.println(objectMapper.writer().writeValueAsString(new A(1, "2")));
    }
}
